/* ----------------------------------------------------------------------
 *	Shadow Quest
 *	Copyright (C) 2009 Prageeth Silva <prageeth@thenewcoders.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  ----------------------------------------------------------------------
 */
package menu;

import java.util.ArrayList;

import menu.MenuButton.ButtonType;

import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import sq.ImageLoader;
import sq.RPG;

/** A submenu for use in Menus
 * 
 */
public class QuestMenu extends SubMenu {

    private static final String TITLE = "Quests";

    /** Create a new SubMenu object
     * @param menu The Menu in which the submenu exists
     */
    public QuestMenu(Menu menu)
            throws SlickException {

        super(menu, new ArrayList<MenuTab>(), QuestMenu.TITLE, false);

    }

    @Override
    protected void loadButtons()
            throws SlickException {

        // TODO change the file of the button image
        String dirPath = "assets/menu/submenu/", hover = "hover_", file = "start.png";

        Image nor = ImageLoader.getLoadedImage(dirPath + file);
        Image hov = ImageLoader.getLoadedImage(dirPath + hover + file);

        MenuButton b = new MenuButton(nor, hov, (RPG.getScreenWidth() - nor.getWidth()) / 2, 486, ButtonType.START);
        b.setShown(true);
        this.getButtons().add(b);

    }

    @Override
    public void update(Input input, boolean mousepress, int delta)
            throws SlickException {

        super.update(input, mousepress, delta);

        if (this.isShowing() && !this.isOpening() && !this.isClosing()) {
            // check for Quest
            if (this.getMenuState() == ButtonType.START) {
                this.getMenu().setMenuState(ButtonType.START);
                this.setMenuState(ButtonType.NONE);
                QuestTab t = (QuestTab) this.getTabs().get(this.getCurrentTab());
                this.getMenu().setSelectedQuest(t.getQuest());
            }
        }

    }
}
